package cqrtplm.listener;

import cn.hutool.core.convert.Convert;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.hustcad.plm.pdm.workflow.annotion.CustomListener;
import com.hustcad.plm.pdm.workflow.model.constant.ProcessConstant;
import cqrtplm.service.ExpiredOldVersionsService;
import cqrtplm.service.FromDataService;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;

/**
 * @author fxw
 * @version 1.0
 * @ClassName LnvalidAllHistoricalVersionsListener
 * @Description TODO
 * @since 2025/11/19 10:24
 */
@Slf4j
@CustomListener(category = "润通", description = "失效历史版本")
public class LnvalidAllHistoricalVersionsListener implements ExecutionListener {
    @Override
    public void notify(DelegateExecution delegateExecution) {
        log.info("----执行失效历史版本 开始----");

        long l = System.currentTimeMillis();
        String workFlowContainerId = delegateExecution.getProcessInstanceBusinessKey();
        if (StringUtils.isBlank(workFlowContainerId)) {
            workFlowContainerId = delegateExecution.getVariable(ProcessConstant.WORK_FLOW_CONTAINER_ID).toString();
        }
        log.info("流程失效历史版本:{}", workFlowContainerId);

        ExpiredOldVersionsService expiredOldVersionsService = SpringUtil.getBean(ExpiredOldVersionsService.class);
        expiredOldVersionsService.performAnInvalidHistoricalVersion(Convert.toBigInteger(workFlowContainerId));


        log.info("----执行失效历史版本:{}----", System.currentTimeMillis() - l);
    }

}
